package net.aiform.template.pojo;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import net.aiform.bean.Constant;
import net.aiform.pojo.Identity;
import net.aiform.record.pojo.Record;
import net.aiform.security.pojo.FormAccessController;

@Entity
@Table(name = "af_template")
public class Template extends Identity implements Serializable {
	public static final String AC_RECORD = "t.record";
	public static final String AC_RESULT = "t.result";
	public static final String AC_STATISTICS = "t.stat";
	private static final long serialVersionUID = -5684761830352662130L;
	private long creator;
	private String category;
	private Date recordStart;
	private Date recordEnd;
	private Date statisticsStart;
	private Date statisticsEnd;
	private int fieldsAmount;
	@OneToMany(mappedBy = "template", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	private Set<FormAccessController> formAccessControllers;
	private String header;
	private String footer;
	private String valueTable;
	private boolean random;
	private boolean recordUser;
	private boolean recordIp;
	private boolean recordTime;
	@OneToMany(mappedBy = "template", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	private Set<Field> fields;
	@Transient
	private Set<Record> recordes;

	public String getValueTableObject() {
		return Constant.PREFIX_VALUE_TABLE_OBJECT + getValueTable();
	}

	public String getTable() {
		return Constant.PREFIX_VALUE_TABLE + getValueTable();
	}

	public Set<Field> getFields() {
		return fields;
	}

	public int getFieldsAmount() {
		return fieldsAmount;
	}

	public String getFooter() {
		return footer;
	}

	public String getHeader() {
		return header;
	}

	public Date getRecordEnd() {
		return recordEnd;
	}

	public Date getRecordStart() {
		return recordStart;
	}

	public Date getStatisticsEnd() {
		return statisticsEnd;
	}

	public Date getStatisticsStart() {
		return statisticsStart;
	}

	public boolean isRandom() {
		return random;
	}

	public boolean isRecordIp() {
		return recordIp;
	}

	public boolean isRecordTime() {
		return recordTime;
	}

	public boolean isRecordUser() {
		return recordUser;
	}

	public void setFields(Set<Field> fields) {
		this.fields = fields;
	}

	public void setFieldsAmount(int fieldsAmount) {
		this.fieldsAmount = fieldsAmount;
	}

	public void setFooter(String footer) {
		this.footer = footer;
	}

	public void setHeader(String header) {
		this.header = header;
	}

	public void setRandom(boolean random) {
		this.random = random;
	}

	public void setRecordEnd(Date recordEnd) {
		this.recordEnd = recordEnd;
	}

	public void setRecordIp(boolean recordIp) {
		this.recordIp = recordIp;
	}

	public void setRecordStart(Date recordStart) {
		this.recordStart = recordStart;
	}

	public void setRecordTime(boolean recordTime) {
		this.recordTime = recordTime;
	}

	public void setRecordUser(boolean recordUser) {
		this.recordUser = recordUser;
	}

	public void setStatisticsEnd(Date statisticsEnd) {
		this.statisticsEnd = statisticsEnd;
	}

	public void setStatisticsStart(Date statisticsStart) {
		this.statisticsStart = statisticsStart;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public long getCreator() {
		return creator;
	}

	public void setCreator(long creator) {
		this.creator = creator;
	}

	public Set<FormAccessController> getFormAccessControllers() {
		return formAccessControllers;
	}

	public void setFormAccessControllers(Set<FormAccessController> formAccessControllers) {
		this.formAccessControllers = formAccessControllers;
	}

	public Set<Record> getRecordes() {
		return recordes;
	}

	public void setRecordes(Set<Record> recordes) {
		this.recordes = recordes;
	}

	public String getValueTable() {
		return valueTable;
	}

	public void setValueTable(String valueTable) {
		this.valueTable = valueTable;
	}

	@Override
	public String toString() {
		return "Template [category=" + category + ", creator=" + creator + ", fields=" + fields + ", fieldsAmount=" + fieldsAmount + ", footer=" + footer + ", formAccessControllers="
				+ formAccessControllers + ", header=" + header + ", random=" + random + ", recordEnd=" + recordEnd + ", recordIp=" + recordIp + ", recordStart=" + recordStart + ", recordTime="
				+ recordTime + ", recordUser=" + recordUser + ", recordes=" + recordes + ", statisticsEnd=" + statisticsEnd + ", statisticsStart=" + statisticsStart + ", valueTable=" + valueTable
				+ "]";
	}

}
